<template>
  <div class="newGoods">
    <div class="title">
      <div :class="{'title-item':true, 'active':isNew }"
        @click="isNew=true"
      >
        <span>
          最新上架
        </span> 
      </div>
      <div :class="{'title-item':true, 'active':!isNew }" @click="isNew=false" >
          <span>
            即将结束
          </span>
      </div>
    </div>
    <div class="goodsList">
      <GoodsItem :goodsInfo="item" v-for="(item, index) in listData" :key="index" />
    </div>

  </div>
</template>

<script>
import { getNewGoods } from 'server/front_k.js'


import GoodsItem from 'components/common/goodsItem/GoodsItem'


export default {
  data() {
    return {
      isNew:true,
      itemData1:[],
      itemData2:[],
    }
  },
  components:{
    GoodsItem
  },
  computed: {
    listData(){
      if (this.isNew) {
        return this.itemData1
      }else{
        return this.itemData2

      }

    }
  },
  methods:{
    _getNewGoods(){
      getNewGoods().then(res=>{

        if (res.err_code == 1000) {
          this.itemData1 =  res.data[0]
          this.itemData2 =  res.data[1]
        }

      })

    }
  },
  created(){
    this._getNewGoods()

  }
  

}
</script>

<style scoped>
.title {
  display: flex;
  margin-top: 30px;
}
.title>:nth-child(1){
  border-right: 1px solid #ccc;
}
.title-item {
  width: 150px;
  display: flex;
  /* justify-content: center; */
  align-items: center;
  font-size: 22px;
  font-weight: 600;
  color: #000;
  text-align: center;
  cursor: pointer;
}
.title-item span {
  padding: 10px  20px;
  text-align: center;
}
.active span{
  background: #3fe0ad;
  border-radius: 10px;
  color: #fff;
}
.goodsList{
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
}
</style>